//
//  HCCenterView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/21.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCCenterView.h"

@implementation HCCenterView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubview:frame];
    }
    return self;
}

-(void)initializeSubview:(CGRect)frame {
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, YBKAdaptiveW(88))];
    image.image = [UIImage imageNamed:@"happy_center_bg"];
    image.userInteractionEnabled = YES;
    [self addSubview:image];
    
    UIButton *button_left = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width/2.0, image.frame.size.height)];
    button_left.tag = 1;
    [image addSubview:button_left];
    
    UIButton *button_right = [[UIButton alloc] initWithFrame:CGRectMake(button_left.frame.size.width, 0, button_left.frame.size.width, button_left.frame.size.height)];
//    button_right.backgroundColor = [UIColor redColor];
    button_right.tag = 2;
    [image addSubview:button_right];
    
    [button_right addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [button_left addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)btnAction:(UIButton *)btn {
    if (btn.tag == 1) {
        NSLog(@"在线客服");
        [self.delegate clicked];
    }else{
        NSLog(@"客服热线");
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"4000616123"]];
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"4000616123"];
        //            NSLog(@"str======%@",str);
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
